﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using System.Text;

namespace DataBind
{
    public partial class _Default : System.Web.UI.Page
    {
        public IEnumerable<IDictionary> GenerateData()
        {
            for (var i = 0; i < 10; i++)
            {
                var dict = new Dictionary<string, object>();
                dict["ID"] = Guid.NewGuid();
                dict["Name"] = "Name_" + i;
                dict["Index"] = i;
                dict["IsEven"] = (i % 2 == 0);
                yield return dict;
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
                BindGrid();
        }

        public void BindGrid()
        {
            IEnumerable list = DataSourceCreator.ToDataSource(GenerateData());
            dynamic d = list;
            LabelDeneme.Text = d[0].ID.ToString();
            grvDatabind.DataSource = d;
            grvDatabind.DataBind();
            Deneme();
        }

        private void Deneme()
        {
            for (int i = 0; i < 5; i++)
            {

                LiteralDeneme.Text += String.Format(@"  <h2>
                                            About
                                        </h2>
                                        <h5>
                                            {0}
                                        </h5>", DateTime.Now.ToString());
            }
        }

        protected void btnTrial_Click(object sender, EventArgs e)
        {

            StringBuilder sb = new StringBuilder();
            sb.Append("window.open('http://localhost/','','left=300,top=400,resizable=0,scrollbars=1,width=710,height=680');");

            ScriptManager.RegisterClientScriptBlock(this.btnTrial, this.GetType(), "hello", sb.ToString(), true);
        }
    }
}
